module.exports = {
    publicPath: process.env.NODE_ENV === 'production'? './': '/',
    productionSourceMap: process.env.NODE_ENV !== 'production',
    lintOnSave: false,
    devServer:{
        proxy:{
            [process.env.VUE_APP_API_BASE_URL]:{
                target: process.env.VUE_APP_API_PROXY,
                ws: true,
                changOrigin:true,
                pathRewrite:{
                    [process.env.VUE_APP_API_BASE_URL] : ''
                },
                onProxyReq: function(proxyReq, req, res) {
                    const token = req.headers['zdan_token']
                    proxyReq.setHeader('ZDAN_Token', token)
                }
            }
        },
    },
    chainWebpack: config => {
        if (process.env.NODE_ENV === "production") {
            // 删除系统默认的splitChunk
            config.optimization.delete("splitChunks");
        }
        config.plugin('html').tap(args => {
            args[0].title = '流媒体管理';
            return args;
        });
        
    },
    configureWebpack: config => {
        // 给输出的js名称添加hash
        config.output.filename = "static/js/[name].[hash].js";
        config.output.chunkFilename = "static/js/[name].[hash].js";
        config.optimization = {
          splitChunks: {
            cacheGroups: {
              // 抽离所有入口的公用资源为一个chunk
              common: {
                name: "chunk-common",
                chunks: "initial",
                minChunks: 2,
                maxInitialRequests: 5,
                minSize: 0,
                priority: 1,
                reuseExistingChunk: true,
                enforce: true
              },
              element: {
                name: "chunk-element-ui",
                test: /[\\/]node_modules[\\/]element-ui[\\/]/,
                chunks: "all",
                priority: 3,
                reuseExistingChunk: true,
                enforce: true
              },
            }
          }
        };
    },
}